package com.itheima.jobs;

import cn.hutool.core.collection.CollectionUtil;
import com.itheima.utils.QiNiuUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

@Component
public class ClearImages {
    @Autowired
    JedisPool jedisPool;

    public void clear() {
        Set<String> sdiff = jedisPool.getResource().sdiff("setmealPicResources", "setmealPicDbResources");
        if (CollectionUtil.isNotEmpty(sdiff)) {
            for (String s : sdiff) {
                QiNiuUtil.delete(s);
                jedisPool.getResource().srem("setmealPicResources",s);
            }
        }
    }
}
